package vn.igolf.distance;
import java.awt.AWTEvent;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;


public class LoginPanel extends JPanel implements ActionListener{
	
	private JTextField user;
	private JTextField pass;
	private JButton loginBtn;
	
    public LoginPanel()    {
    	setLayout(new FlowLayout());
        user = new JTextField("user",20);
        pass = new JTextField("pass",20);
        loginBtn = new JButton("Login");
        add (user);
        add (pass);
        add (loginBtn);
        loginBtn.addActionListener(this);
    }

	@Override
	public void actionPerformed(ActionEvent e) {
		String s_user = user.getText();
		String s_pass = pass.getText();
		
		JFrame frame = (JFrame) SwingUtilities.getRoot(this);
		if (s_user.equals("user") && (s_pass.equals("pass"))) {
			// authenticate ok
            //Create and set up the content pane.
          JComponent holePlayPane = new HolePlayPanel();
          holePlayPane.setOpaque(true); //content panes must be opaque
          frame.setContentPane(holePlayPane);
          
          frame.setSize( holePlayPane.getSize());
          frame.setVisible(true);

		} else {
			// authenticate not ok
			frame.setVisible(false);
			frame.dispose();		
		}
	}
}